package freecomm.study.tabtest;

import java.util.ArrayList;
import java.util.List;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;

public class TabTest extends TabActivity implements TabContentFactory
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        TabHost tabHost = getTabHost();
        LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);
        tabHost.addTab(tabHost.newTabSpec("all").setIndicator("所有通话记录").setContent(this));
        tabHost.addTab(tabHost.newTabSpec("OK").setIndicator("已接来电").setContent(this));
        tabHost.addTab(tabHost.newTabSpec("cancel").setIndicator("未接来电").setContent(this));
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) tabHost.getTabWidget().getLayoutParams();

        // tabHost.getTabWidget().setLayoutParams(params);
    }

    @Override
    public View createTabContent(String tag)
    {

        ListView lv = new ListView(this);
        List<String> list = new ArrayList<String>();
        list.add(tag);
        if (tag.equals("all"))
        {
            list.add("所有通话记录1");
            list.add("所有通话记录2");
            list.add("所有通话记录3");
            list.add("所有通话记录4");
        } else if (tag.equals("OK"))
        {
            list.add("已接来电1");
            list.add("已接来电2");
            list.add("已接来电3");
        } else
        {
            list.add("未接来电1");
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_checked, list);
        lv.setAdapter(adapter);
        return lv;
    }
}